home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 6.0 KB | 207 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWResAcc.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWRESACC_H
- #define FWRESACC_H
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWPRVRAC_H
- #include "FWPrvRAc.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWRESFIL_H
- #include "FWResFil.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
- #include <windows.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
- #include <Types.h>
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CResource
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CResource FW_AUTO_DESTRUCT_OBJECT
- {
- public:
-
- ~ FW_CResource();
- // Decrements the reference count.
- // Delete the resource access ref if count goes to zero.
-
- FW_CResource(const FW_CResourceFile &file,
- FW_ResourceId resourceId,
- FW_ResourceType resourceType);
- // Creates a new FW_CPrivResourceRep attached to the given resource.
-
- FW_CResource(const FW_CResource& other);
- // Copy constructor.
-
- FW_CResource& operator=(const FW_CResource& other);
- // Assignment operator.
-
- unsigned long GetSize() const;
- // Return the size of this resource in bytes.
-
- void* GetData();
- // Low level method. Clients should generally use FW_CAcquireResourceData objects.
- // Lock the resource and return a pointer to the data.
- // Client assumes responsiblity to call ReleaseData.
-
- void ReleaseData();
- // Low level method. Clients should generally use FW_CAcquireResourceData objects.
- // Unlock the resource.
-
- FW_ResourceHandle GetResourceHandle() const;
- // Low level method. Clients should generally use FW_CAcquireResourceData objects.
- // Return the platform (native) handle.
- // This method should be used with caution, since it reveals platform specifics,
- // and allows violation of internal lock counts, etc.
-
- private:
-
- FW_PPrivResourceAccess fPrivResourceAccess;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CResource::operator=
- //----------------------------------------------------------------------------------------
-
- inline FW_CResource& FW_CResource::operator=(const FW_CResource& other)
- {
- fPrivResourceAccess = other.fPrivResourceAccess;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CResource::GetSize
- //----------------------------------------------------------------------------------------
-
- inline unsigned long FW_CResource::GetSize() const
- {
- return fPrivResourceAccess->GetSize();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CResource::GetData
- //----------------------------------------------------------------------------------------
-
- inline void* FW_CResource::GetData()
- {
- return fPrivResourceAccess->GetData();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CResource::ReleaseData
- //----------------------------------------------------------------------------------------
-
- inline void FW_CResource::ReleaseData()
- {
- fPrivResourceAccess->ReleaseData();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CResource::GetResourceHandle
- //----------------------------------------------------------------------------------------
-
- inline FW_ResourceHandle FW_CResource::GetResourceHandle() const
- {
- return fPrivResourceAccess->GetResourceHandle();
- }
-
-
- //========================================================================================
- // CLASS FW_CAcquireResourceData
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CAcquireResourceData FW_AUTO_DESTRUCT_OBJECT
- {
-
- public:
-
- FW_CAcquireResourceData(FW_CResource resource);
- // Acquires the data using resource->GetData().
-
- ~ FW_CAcquireResourceData();
- // Releases the data using resource->ReleaseData().
-
- void *GetData() const;
- // Returns a void* pointer to the data.
-
- unsigned long GetSize() const;
- // Returns the size of the resource, in bytes.
-
- private:
-
- FW_CResource fResource;
- // The resource.
-
- void* fData;
- // The acquired data.
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireResourceData::GetData
- //----------------------------------------------------------------------------------------
-
- inline void* FW_CAcquireResourceData::GetData() const
- {
- return fData;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CAcquireResourceData::GetSize
- //----------------------------------------------------------------------------------------
-
- inline unsigned long FW_CAcquireResourceData::GetSize() const
- {
- return fResource.GetSize();
- }
-
- //========================================================================================
- // Global Utility Functions
- //========================================================================================
-
- // These functions will probably be moved into the Strings component.
- // To do so, we will make Strings be dependent on the Streams component,
- // and then provide "load string from sink" functions.
-
- void FW_FUNC_ATTR FW_LoadStringByPosition(FW_CResourceFile &file,
- FW_ResourceId resourceId,
- FW_ResourceType resourceType,
- unsigned short position,
- FW_CString &string);
-
- void FW_FUNC_ATTR FW_LoadStringByID(FW_CResourceFile &file,
- FW_ResourceId resourceId,
- FW_ResourceType resourceType,
- unsigned long id,
- FW_CString &string);
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-